#include "gtest/gtest.h"
#include <string>
#include <acapella/worker/task_base.hpp>

using namespace acapella::worker;
using namespace acapella::delegate;

std::string TaskTestFunction(const std::string& str)
{
    return str;
}

TEST(testTask, compileTest)
{

}

TEST(testTask, normalSyncTaskRunTest)
{
    typedef delegate<std::string(const std::string&)> delegate_type;

    typedef acapella::shared_ptr<delegate_type> delegate_pointer;

    std::string testString = "hello world";

    delegate_pointer pDelegate(new delegate_type(
                                   delegate_type::functor_type(&TaskTestFunction),
                                   testString));

    std::string str = pDelegate->Do();
    EXPECT_EQ("hello world", str);

    str = "";

    SyncTask<delegate_type, acapella::synchronize::_default_::semaphore> syncTask(pDelegate, str);
    syncTask.run();

    syncTask.wait();

    EXPECT_EQ("hello world", str);
}
